package com.meichis.yndms.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import com.meichis.mcsappframework.adapter.recyclerview.CommonAdapter;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.mcsappframework.widget.ZoomImageView;
import com.meichis.yndms.R;
import com.meichis.yndms.common.MCode;
import com.meichis.yndms.model.FeedBack;
import com.meichis.yndms.model.Picture;
import com.meichis.yndms.ui.activity.TerminalFeedbackDetailActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.List;

public class TerminalFeedbackAdapter extends CommonAdapter<FeedBack> {

    private DisplayImageOptions options;

    public TerminalFeedbackAdapter(Context context, int layoutId, List<FeedBack> datas) {
        super(context, layoutId, datas);
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.emptyphoto)
                .showImageForEmptyUri(R.mipmap.emptyphoto)
                .showImageOnFail(R.mipmap.emptyphoto).cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .cacheOnDisk(true).considerExifParams(true)
                .build();
    }

    @Override
    protected void convert(ViewHolder holder, FeedBack feedBack, int position) {
        holder.setText(R.id.tv_clientName, feedBack.getOwnerClientName());
        holder.setText(R.id.tv_content, feedBack.getContent());
        holder.setText(R.id.tv_date, feedBack.getInsertTime());
        holder.setText(R.id.tv_state, feedBack.getStateName());
        holder.setText(R.id.tv_classify, feedBack.getClassifyName());

        FeedBack.AttsBean attsBean = null;
        if (feedBack.getAtts() != null && feedBack.getAtts().size() > 0) {
            attsBean = feedBack.getAtts().get(0);
        }

        holder.setOnClickListener(R.id.ll_item, v -> {
            Intent intent = new Intent(mContext, TerminalFeedbackDetailActivity.class);
            intent.putExtra(MCode.ID, feedBack.getID());
            mContext.startActivity(intent);
        });

        Picture picture = new Picture();
        picture.setGuid(attsBean.getGuid());
        ZoomImageView view = holder.getView(R.id.pic);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.displayImage(attsBean.getUrl(), options);
    }


}
